﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="VehiclesDocument.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the VehiclesDocument type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Windows.Client.Documents
{
    using System;
    using System.Diagnostics.Contracts;
    using Common;
    using View;
    using ViewModel;

    /// <summary>
    /// Defines the <seealso cref="VehiclesDocument"/> type.
    /// </summary>
    public class VehiclesDocument : Document
    {
        /// <summary>
        /// Vehicle view model
        /// </summary>
        private readonly VehiclesViewModel _viewModel;

        /// <summary>
        /// Initializes a new instance of the <see cref="VehiclesDocument"/> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        public VehiclesDocument(VehiclesViewModel viewModel)
            : base("Vehicles")
        {
            Contract.Requires<ArgumentNullException>(viewModel != null);
            _viewModel = viewModel;
            View = new VehiclesView { DataContext = _viewModel };
            ContextMenuGroupName = "cmVehicle";

            VehiclesViewModel.RefreshCommand.RegisterPotentialTarget(View.ActiveAwareness, _viewModel.RefreshList);
            VehiclesViewModel.EditCommand.RegisterPotentialTarget(View.ActiveAwareness, _viewModel.EditVehicle, _viewModel.CanEditVehicle);
            VehiclesViewModel.DeleteCommand.RegisterPotentialTarget(View.ActiveAwareness, _viewModel.DeleteVehicle, _viewModel.CanDeleteVehicle);
        }

        /// <summary>
        /// Documents the closed.
        /// </summary>
        public override void DocumentClosed()
        {
            VehiclesViewModel.RefreshCommand.UnregisterPotentialTarget(View.ActiveAwareness);
            VehiclesViewModel.EditCommand.UnregisterPotentialTarget(View.ActiveAwareness);
            VehiclesViewModel.DeleteCommand.UnregisterPotentialTarget(View.ActiveAwareness);
        }
    }
}